/**
 * 
 */
package com.revenco.bi.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.revenco.bi.controller.basecontroller.AbstractUserAwareController;
import com.revenco.bi.service.TnChartBaseinfoService;
import com.revenco.bi.service.TnChartDataitemsService;
import com.revenco.bi.service.TnChartParamsService;
import com.revenco.bi.util.Json;

/**
 * @author LingJun
 * @version $Revision:1.0.0, 2014年2月14日 上午11:45:06 
 */
@Controller
public class ChartManager extends AbstractUserAwareController {
	@Autowired
	private TnChartBaseinfoService tnChartBaseinfoService;
	@Autowired
	private TnChartDataitemsService tnChartDataitemsService;
	@Autowired
	private TnChartParamsService tnChartParamsService;
	
	@RequestMapping(value = "/deleteChart", produces = "text/plain;charset=UTF-8")
	@ResponseBody
	public String deleteById(@RequestParam("id") String chartId) throws Exception {
		StringBuilder result = new StringBuilder("");
//		result.append("[");
		if(this.tnChartBaseinfoService.deleteById(chartId)) {
			this.tnChartDataitemsService.deleteByChartId(chartId);
			this.tnChartParamsService.deleteByChartId(chartId);
			result.append("{");
			Json.addProperty(result, "success", true);
			result.append("}");
		} else {
			result.append("{");
			Json.addProperty(result, "success", false);
			result.append(",");
			Json.addProperty(result, "msg", "Sorry delete failured!");
			result.append("}");
		}
		log.info("delete chart result: {}", result.toString());
		return result.toString();
	}
}
